package com.zzb.servlet.comment;

import com.alibaba.fastjson.JSONObject;
import com.zzb.DTO.ResultDTO;
import com.zzb.VO.CommentVO;
import com.zzb.service.CommentService;
import com.zzb.service.impl.CommentServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/back/comment/add")
public class CommentAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        //得到前端数据
        String title = req.getParameter("title");
        String userId = req.getParameter("userId");
        String enable = req.getParameter("enable");


        //对前端数据进行封装
        CommentVO commentVO = new CommentVO();
        //调用服务逻辑
        CommentService commentService = new CommentServiceImpl();
        //得到返回值
        ResultDTO resultDTO = commentService.add(commentVO);
        //响应
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
